package opreation;

import book.Book;
import book.BookList;

import java.util.Scanner;

public class RmoveOpreation implements IOpreation{
    @Override
    public void work(BookList booklist) {
        //System.out.println("下架图书");
        System.out.println("请输入需要下架书的名字");
        Scanner scanner = new Scanner(System.in);
        String name = scanner.nextLine();
        int size = booklist.getUsedsize();
        int i =0;
        for (i=0; i < size; i++) {
            Book book = booklist.getBooks(i);
            if(book.getName().equals(name)) {
                break;
            }
        }
        if(i>=size) {
            System.out.println("需要下架的书不存在！");
            return;
        }
        //开始删除该书
        for (int j = i; j < size; j++) {
            Book book = booklist.getBooks(j+1);
            booklist.setBooks(book,j);
        }
        booklist.setBooks(null,size-1);
        booklist.setUsedsize(size-1);
        System.out.println("下架成功");

    }
}
